package com.zt.controller;

import com.alibaba.excel.EasyExcel;
import com.zt.anno.LogOperation;
import com.zt.excel.StudentListener;
import com.zt.pojo.*;
import com.zt.service.EmpService;
import com.zt.service.impl.StudentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 员工管理
 */
@RequestMapping("/emps")
@RestController
public class EmpController {

    @Autowired
    private EmpService empService;

    // 分页查询
    @GetMapping
    public Result QueryPage(EmpQueryParam empQueryParam){
        PageResult pageResult = empService.QueryPage(empQueryParam);
        return Result.success(pageResult);
    }
    // 批量删除
    @DeleteMapping
    @LogOperation
    public Result deleteById(@RequestParam("ids") Integer[] id){
        empService.deleteById(id);
        return Result.success();
    }
    // 添加员工
    @PostMapping
    @LogOperation
    public Result add(@RequestBody Emp emp){
        empService.add(emp);
        return Result.success();
    }
    //查询全部员工
    @GetMapping("/list")
    public Result findAll(){
        List<Emp> empList = empService.findAll();
        return Result.success(empList);
    }
    //根据id查询员工
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        Emp emp = empService.findById(id);
        return Result.success(emp);
    }

    // 修改员工
    @PutMapping
    @LogOperation
    public Result update(@RequestBody Emp emp){
        empService.update(emp);
        return Result.success();
    }

    //修改员工密码
    @PutMapping("/changePassword")
    @LogOperation
    public Result updatePassword(@RequestBody Password password){
        empService.updatePassword(password);
        return Result.success();
    }
}